const { resolve } = require('path')

 const ExtractTextPlugin = require('extract-text-webpack-plugin');
// const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack');
const path =require('path');

var node_env=process.env.node_env.trim() || 'development';

var jquery=path.resolve(__dirname,'../src/lib/jquery.min.js')

csspath="../dist/css/"

var mole={
  //devtool: 'source-map',
  context: resolve(__dirname , "../src"),
  // 配置页面入口js文件
  entry: {
    'bundle.client':['./client'],
    vendor: ['vue', 'vue-router','vue-resource','jquery']
  },
  // 配置打包输出相关
  output: {
    // 打包输出目录
    path: resolve(__dirname, '../dist/'),
    publicPath: '/',
    // 入口js的打包输出文件名
    filename: '[name].js'
  },
  module: {
    rules: [
      { test: /iview.src.*?js$/, use: ['babel'] },
      {
        test: /muse-ui.src.*?js$/,
        use: ['babel']
      },
      {
            test: /\.vue$/,
            use:[
              {
                loader:'vue-loader',
                options: {//.vue 内css 打包
                  loaders: {
                      css: 'css-loader',
                      lcss:['css-loader','less-loader']
                  }
                }
              } 
            ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [{
          loader: "babel-loader",
          options: { presets: ["es2015"] }
        }]
      },{
        test:/\.css$/,
        //use:['style-loader','css-loader']
        use:ExtractTextPlugin.extract({
          fallback:'style-loader',
          use:'css-loader',
        })
      },{
        test:/\.(less|lcss)$/,
        //use:['style-loader','css-loader','less-loader']
        use:ExtractTextPlugin.extract({
          fallback:'style-loader',
          use:['css-loader','less-loader'],
        })
      },{
        test: /\.(png|jpg|jpeg|gif)(\?.+)?$/,
        use:['file-loader?limit=8192&name=images/[name].[ext]'] 
      },
      {
        test: /\.(eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
        use:['file-loader?limit=8192&name=fonts/[name].[ext]'] 
      },
      {test: jquery, use: "expose-loader?$"},
      {test: jquery, use: "expose-loader?jQuery"},
    ]
  },
  
  resolve: {
        extensions: ['.js',  '.css', '.less'],
        //别名设置,主要是为了配和webpack.ProvidePlugin设置全局插件;
        alias: {
            //设置全局jquery插件;
            'jquery':jquery, //绝对路径;
            'platform':node_env,
            'muse-components': 'muse-ui/src',
            'vue': 'vue/dist/vue.js'
        }
  },plugins: [
    
    // 提取 CSS 到单独的文件中
    new ExtractTextPlugin({filename:csspath+'[name].css',allChunks: true}),//设置生成目录和名，热更新时src 为设置的
    
    new webpack.ProvidePlugin({ 
        "$": 'jquery'
    }),
    
  ],
  externals: {
    jQuery: 'jquery'
  }

}

module.exports = mole